/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.比较含退格的字符串;

import java.util.LinkedList;

public class Main {
    LinkedList<Character> middle1 = new LinkedList<>(), middle2 = new LinkedList<>();

    public boolean backspaceCompare(String s, String t) {
        for (char c : s.toCharArray()) {
            if (c == '#') {
                middle1.pollLast();
            } else
                middle1.addLast(c);
        }
        for (char c : t.toCharArray()) {
            if (c == '#') {
                middle2.pollLast();
            } else
                middle2.addLast(c);
        }
        if (middle1.size() != middle2.size())
            return false;
        for (Character character : middle1) {
            if (character != middle2.pollFirst())
                return false;
        }
        return true;
    }
}
